package com.pro.common.service.websocket.util;

import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.net.InetAddress;
@Component
@Slf4j
public class IPAddressUtil {
    @Autowired
    private Environment environment;
    public String getServerAddress() {
        try {
            String ip = InetAddress.getLocalHost().getHostAddress();
            String port = environment.getProperty("local.server.port");
            return ip + ":" + port;
        } catch (Exception e) {
            log.warn("获取服务IP和端口失败", e);
            return null;
        }
    }
}
